package cn.xfdzx.android.apps.shop.adapter;

import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.bean.AfterSalesListRetailBean;

/**
 * Creator: zf.
 * Date: 2020/9/24.
 * Description:零售-售后列表-内部商品图片适配器.
 */
public class AfterSalesListRetail_InnergoodsAdapter extends BaseQuickAdapter<AfterSalesListRetailBean.DataBean.ApplyBean.ApplyCartBean, BaseViewHolder>  {
    private List<AfterSalesListRetailBean.DataBean.ApplyBean.ApplyCartBean> applyCart;
    public AfterSalesListRetail_InnergoodsAdapter(@Nullable List<AfterSalesListRetailBean.DataBean.ApplyBean.ApplyCartBean> data) {
        super(R.layout.item_all_order_goods, data);
    }

    @Override
    public void setData(int index, @NonNull AfterSalesListRetailBean.DataBean.ApplyBean.ApplyCartBean data) {
        super.setData(index, data);
    }


    @Override
    protected void convert(final BaseViewHolder viewHolder, final AfterSalesListRetailBean.DataBean.ApplyBean.ApplyCartBean date) {
        ImageView iv_shop = viewHolder.getView(R.id.iv_goods);
        RoundedCorners roundedCorners = new RoundedCorners(20);
        //通过RequestOptions扩展功能,override:采样率,因为ImageView就这么大,可以压缩图片,降低内存消耗
        RequestOptions options = RequestOptions.bitmapTransform(roundedCorners).override(200, 200);
        options.placeholder(R.drawable.icon_defult)//图片加载出来前，显示的图片
                .fallback(R.drawable.icon_defult) //url为空的时候,显示的图片
                .error(R.drawable.icon_defult);

        if (null != date.getGoods_img()) {
            Glide.with(mContext).load(date.getGoods_img()).apply(options.transform(new CenterCrop(), roundedCorners)).into(iv_shop);
        }
    }
    public void clearDatas(){
        mData.clear();
        notifyDataSetChanged();
    }
    public void refreshDatas(List<AfterSalesListRetailBean.DataBean.ApplyBean.ApplyCartBean> list){
        super.replaceData(list);
    }

}
